<template>
  <div>
    <el-tabs type="border-card" v-loading="loading">
      <el-tab-pane v-for="check in checkes" :key="check.plat" :label="check.plat">
        <el-row>
          <el-col :span="12">
            <el-result :icon="check.pushStatus === '1' ? 'success' : 'error'">
              <template #title>
                <p>{{ check.pushStatus === '1' ? '发布成功' : '发布失败' }}</p>
              </template>
              <template #sub-title>
                <p>发布版本：{{ check.versionCode }} ( {{ check.pushType === '1' ? '平台发布' : '在线发布' }} ) </p>
              </template>
              <template #extra>
                <p>{{ check.pushStatusDesc }}</p>
              </template>
            </el-result>
          </el-col>
          <el-col :span="12">
            <el-result
              :icon="
                check.checkStatus === '' ? 'warning' : check.checkStatus === '1' ? 'success' : 'error'
              "
              :sub-title="'在线版本：' + check.versionCode"
            >
              <template #title>
                <p v-if="check.checkStatus === '1'">审核通过</p>
                <p v-if="check.checkStatus === '2'">审核不通过</p>
                <p v-if="check.checkStatus === '3'">审核中</p>
                <p v-if="check.checkStatus === '4'">应用下架</p>
              </template>
              <template #extra>
                <p>{{ check.checkStatusDesc }}</p>
              </template>
            </el-result>
          </el-col>
        </el-row>
      </el-tab-pane>
      <el-empty v-show="noData" description="未发布版本" />
    </el-tabs>
    <el-button color="#626aef" style="margin-top:10px;" @click="syncCheckInfo()">同步在线审核结果</el-button>
  </div>
</template>

<script lang="ts" setup>
import { onBeforeMount, ref } from 'vue'
import { GetCheckInfoApi, SyncCheckInfoApi } from '@/api'
import { useCounterStore } from '@/stores/manage'
import { ElLoading } from 'element-plus'

const manager = useCounterStore()
// 加载中
const loading = ref(true)
const noData = ref(false)

interface CheckData {
  plat: string
  versionCode: string
  pushStatus: string
  pushStatusDesc: string
  pushType: string
  checkStatus: string
  checkStatusDesc: string
}

const checkes = ref<CheckData[]>([])

// 初始化加载
onBeforeMount(() => {
  getCheckInfo()
})

// 获取审核信息
const getCheckInfo = () => {
  GetCheckInfoApi(manager.getAppId())
  .then((response) => {
    const result = response.data
    if (result.code == 200) {
      const data = result.data
      if (data == null) {
        noData.value = true
      } else {
        checkes.value = data
      }
    }
    loading.value = false
  })
  .catch((error) => {
    console.log(error)
  })
}

// 同步审核结果
const syncCheckInfo = () => {
  loading.value = true
  SyncCheckInfoApi(manager.getAppId())
  .then((response) => {
    const result = response.data
    if (result.code == 200) {
      getCheckInfo()
    }
  })
  .catch((error) => {
    console.log(error)
  })
  .finally(()=>{
    loading.value = false
  })
}


</script>
